package fields;
import game.Player;

public abstract class Ownable extends Field {
	
	protected int price;
	protected Player owner = new Player();
	
	public Ownable (int number, String name, int price)
	{
		super (number,name);
		this.price=price;
		owner=null;
	}
	
	public abstract int getRent();
	
	public void landOnField(Player p)
	{
		if (!isOwnable())
		{
			p.transfer(getRent(), owner);
		}
		else {
			if (p.getChoice()==1) buy(p);
		}
	}
	
	public boolean isOwnable()
	{
		if (owner==null) return true;
		else return false;
	}
	
	public void setOwner(Player s)
	{
		owner=s;
	}
	
	public boolean isOwner(Player p)
	{
		if (getOwner().compareTo(p.getName())==0) return true;
		else return false;
	}
	
	public String getOwner()
	{
		return owner.getName();
	}
	
	public void buy(Player s)
	{
		if (isOwnable()) {
			s.withdraw(price);
			setOwner(s);
		}
	}
	
	public void forSale()
	{
		owner=null;
	}
	

}
